import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter, AutoMinorLocator
import matplotlib
from scipy.integrate import cumtrapz
from scipy.stats import linregress
from scipy.interpolate import make_interp_spline, BSpline

def temperature(start, stop, date):
    
    temp = pd.read_csv("temperature.csv", sep=";", index_col=0)
    temp.index = pd.to_datetime(temp.index, format='%d/%m/%Y')
    data = temp.loc[temp.index ==date , start:stop]
    # columns = data.columns.tolist()
    x = [x for x in range(0, 24)]
    y = data.values.tolist()[0]
    cm = 5/2.54  # centimeters in inches
    
    fig, ax = plt.subplots(figsize=(15*cm, 5*cm), num="Корреляция погоды и времени",)
    #fig.canvas.set_window_title(800,600)
    ax.set_title("Погода за день", fontsize=16)
    ax.set_xlabel("Часы", fontsize=14, color="red")
    ax.set_ylabel("Градусы по Цельсию", fontsize=14, color="green")
    ax.grid(which="major", linewidth=1)
    ax.grid(which="minor", linestyle="--", color="gray", linewidth=1)
    ax.plot(x, y)
    reg = linregress(x, y)
    ax.axline(xy1=(0, reg.intercept), slope=reg.slope, linestyle="--", color="k")
    ax.legend()
    ymax = max(y)
    xpos = y.index(ymax)
    xmax = x[xpos]

    
    ax.annotate('Максимум', xy=(xmax, ymax), xytext=(xmax, ymax+1),
            arrowprops=dict(facecolor='black', shrink=0.01),
            )
    ymax = min(y)
    xpos = y.index(ymax)
    xmax = x[xpos]
    ax.annotate('Минимум', xy=(xmax, ymax), xytext=(xmax, ymax+1),
            arrowprops=dict(facecolor='black', shrink=0.01),
            )
    xnew = np.linspace (x[0], x[23], 200 ) 
    #define spline
    spl = make_interp_spline (x, y, k= 3 )
    y_smooth = spl (xnew)

    #create smooth line chart 
    plt.plot (xnew, y_smooth)
    ax.xaxis.set_minor_locator(AutoMinorLocator())
    ax.yaxis.set_minor_locator(AutoMinorLocator())
    ax.tick_params(which='major', length=1, width=10)
    ax.tick_params(which='minor', length=1, width=10)
    plt.show()


temperature("0:00","23:00", "27/06/2021")

